Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: Fix random.uniform example comment. #25784

Merged
merged 1 commit into from
May 3, 2021

Conversation

JulienPalard
Copy link
Member

Checked using:

>>> random.uniform(10.0 - sys.float_info.epsilon, 10.0)
10.0

@rhettinger
Copy link
Contributor

rhettinger commented May 1, 2021

Note, the example isn't using two different values.

>>> 10.0 - sys.float_info.epsilon == 10.0
True

Also, I think the docs should be left as-is. The intention was to create a half-open interval. In a small way, this make the docs slightly worse.

Are you responding to a reported user problem?

@JulienPalard
Copy link
Member Author

Note, the example isn't using two different values.

That's right, nice catch. I'm trying to find an example:

from collections import Counter
import math
from random import uniform


start = 0
while True:
    stop = math.nextafter(start, math.inf)
    assert start != stop
    values = Counter([uniform(start, stop) for _ in range(100)])
    assert len(values) == 2
    assert start in values
    assert stop in values
    start = stop

I cannot find an example where the end is not included using the code above, do you have an example where the end is excluded?

Are you responding to a reported user problem?

Yes from docs@.

@rhettinger rhettinger added the needs backport to 3.9 only security fixes label May 3, 2021
@rhettinger rhettinger merged commit 440c025 into python:master May 3, 2021
@miss-islington
Copy link
Contributor

Thanks @JulienPalard for the PR, and @rhettinger for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-25843 is a backport of this pull request to the 3.9 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 3, 2021
(cherry picked from commit 440c025)

Co-authored-by: Julien Palard <julien@palard.fr>
miss-islington added a commit that referenced this pull request May 3, 2021
(cherry picked from commit 440c025)


Co-authored-by: Julien Palard <julien@palard.fr>

Automerge-Triggered-By: GH:JulienPalard
@JulienPalard JulienPalard deleted the mdk/uniform branch October 9, 2021 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip issue skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants